<?php
require_once 'config.inc.php';
$dir = $_SERVER["DOCUMENT_ROOT"].SCRIPT_DIR;
$scripts = array();
function recurseDir($dir){
    $dirroot = $_SERVER["DOCUMENT_ROOT"]."/buzzhub/".$_GET["dir"];
    if(is_dir($dir)){
        if($dh = opendir($dir)){
            while(($file = readdir($dh)) !== false){
                if($file != '.' && $file != '..'){
                    if(!is_dir($dir . $file)){
                        $scripts[] = str_replace($dirroot, '', $dir . "/" . $file);
                    }else{
                        $scripts[] = recurseDir($dir.$file); 
                    }	
		}
            }
    	}else{
            echo "Could not open dir!";
        }
 	closedir($dh);         
    }else{
        echo "Not a dir! - " . $dir;
    }
    return $scripts;
}
function pretty($str){
    return "<pre>" . $str . "</pre>";
}
echo json_encode(recurseDir($dir));
?>